package com.lishe.lishe.net;


import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * @author Created by Bin
 */

public class OkhttpCreateHelper {

    private static CacheInterceptor cacheInterceptor = new CacheInterceptor();
    private static final int TIMEOUT_READ = 20;
    private static final int TIMEOUT_CONNECTION = 10;

    private static OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addNetworkInterceptor(cacheInterceptor)
            .addInterceptor(cacheInterceptor)
            .cache(HttpCache.getCache())
            //time out
            .connectTimeout(TIMEOUT_CONNECTION, TimeUnit.SECONDS)
            .readTimeout(TIMEOUT_READ, TimeUnit.SECONDS)
            .writeTimeout(TIMEOUT_READ, TimeUnit.SECONDS)
            //失败重连
            .retryOnConnectionFailure(true)
            .build();

    static OkHttpClient getOkHttpClient() {
        return okHttpClient;
    }


}
